package com.example.demo.netty.c3;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.DefaultPromise;

import java.util.concurrent.ExecutionException;

/**
 * @description:
 * @author: hhl
 * @createDate: 2024/1/25
 * @version: 1.0
 */
public class TestNettyPromise {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        EventLoop eventLoop = new NioEventLoopGroup().next();
        DefaultPromise<Integer> defaultPromise = new DefaultPromise<>(eventLoop);
        new Thread(()->{
            try {
                Thread.sleep(1000);
                defaultPromise.setSuccess(50);

            } catch (InterruptedException e) {
                e.printStackTrace();
                defaultPromise.setFailure(e);
            }

        }).start();

        System.out.println(defaultPromise.get());

    }
}
